package com.sanjiahantang.youjiarole.module.complain.models.impl;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.common.beans.StringBean;
import com.sanjiahantang.youjiarole.module.complain.beans.ComplainBean;
import com.sanjiahantang.youjiarole.module.complain.models.IComplainModel;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by zy on 2017/10/21.
 */

public class ComplainModel implements IComplainModel {
    @Override
    public void findCustomerComplaint(final Context context, Map<String, Object> params, final CallBack<ComplainBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/customer/complaint/phone/findRoleComplaint", params,
                new BaseDelegate.ResultCallback<ComplainBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(ComplainBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }

    @Override
    public void findCustomerBeComplaint(final Context context, Map<String, Object> params, final CallBack<ComplainBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/customer/complaint/phone/findRoleBeComplaint", params,
                new BaseDelegate.ResultCallback<ComplainBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(ComplainBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }

    @Override
    public void addRoleComplaint(final Context context, Map<String, Object> param, final CallBack<ComplainBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/customer/complaint/phone/addRoleComplaint", param,
                new BaseDelegate.ResultCallback<ComplainBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(ComplainBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }

    @Override
    public void findMaxId(final Context context, Map<String, String> param, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/customer/complaint/phone/findMaxIdForRole", param,
                new BaseDelegate.ResultCallback<StringBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(StringBean response, Object tag) {
                        callBack.onSuccess(response,context,tag);
                    }
                });
    }
}
